package minecraft.xiyu.exchantedbook.procedures;

import minecraft.xiyu.exchantedbook.init.ExchantedBookModEnchantments;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.entity.living.LivingAttackEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber
public class EnterProcedure {

	@SubscribeEvent
	public static void onEntityTick(TickEvent.PlayerTickEvent event) {
		if (event.phase != TickEvent.Phase.END || event.player.level.isClientSide) return;

		ItemStack mainHandItem = event.player.getMainHandItem();
		if (!mainHandItem.isEmpty() && EnchantmentHelper.getItemEnchantmentLevel(ExchantedBookModEnchantments.ETERNITY.get(), mainHandItem) > 0) {
			// 重置耐久度
			mainHandItem.setDamageValue(0);
		}
	}
}

